﻿/***************************************************************************
 *		ElGee Google Chart API Helper
 *		Copyright(C) 2011 by Laurent Geffroy lgeffroy@gmail.com
 * 
 *		This program is free software; you can redistribute it and/or 
 *		modify it under the terms of the GNU General Public License as
 *		published by the Free Software Foundation; either version 2 of 
 *		the License, or (at your option) any later version.
 *		
 *		This program is distributed WITHOUT ANY WARRANTY; without even the
 *		implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
 *		See the GNU General Public License for more details.
 *	
 *      For particular licensing, please contact me at lgeffroy@gmail.com
 *****************************************************************************/
using System;
using System.Text;

namespace ElGee.Google.Charts
{
    /// <summary>
    /// Chart Style Class
    /// </summary>
    public class AreaChartStyle : ChartStyle
    {
        private readonly string[] _gridLinecolorExclusion = { "#cccccc", "#ccc" };
        /// <summary>
        /// Gets or sets the axis titles position.
        /// Where to place the axis titles, compared to the chart area
        /// in - Draw the axis titles inside the the chart area.
        /// out - Draw the axis titles outside the chart area.
        /// none - Omit the axis titles.
        /// </summary>
        /// <value>axisTitlesPosition.</value>
        public TypeOfPosition AxisTitlesPosition { get; set; }

        /// <summary>
        /// Gets or sets the color of the grid line.
        /// The color of the gridlines inside the chart area. Specify a valid HTML color string.
        /// </summary>
        /// <value>gridLineColor</value>
        public string GridLineColor { get; set; }

        /// <summary>
        /// Gets or sets the title position.
        /// Where to place the chart title, compared to the chart area. Supported values:
        /// in - Draw the title inside the chart area.
        /// out - Draw the title outside the chart area.
        /// none - Omit the title.
        /// </summary>
        /// <value>titlePosition</value>
        public TypeOfPosition TitlePosition { get; set; }

        /// <summary>
        /// Gets or sets the width of the line.
        /// Line width in pixels. Use zero to hide all lines and show only the points.
        /// </summary>
        /// <value>lineWidth</value>
        public UInt16 LineWidth { get; set; }

        /// <summary>
        /// Gets or sets the size of the point.
        /// Diameter of data points, in pixels. Use zero to hide all points.
        /// </summary>
        /// <value>pointSize</value>
        public UInt16 PointSize { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether this instance is stacked.
        /// If set to true, line values are stacked (accumulated).
        /// </summary>
        /// <value>
        /// 	<c>true</c> if this instance is stacked; otherwise, <c>false</c>.
        /// </value>
        public bool IsStacked { get; set; }

        /// <summary>
        /// Initializes a new instance of the <see cref="AreaChartStyle"/> class.
        /// </summary>
        public AreaChartStyle() : base()
        {
            AxisTitlesPosition = TypeOfPosition.Undefined;
            TitlePosition = TypeOfPosition.Undefined;
            LineWidth = 1;
            PointSize = 0;
        }

        /// <summary>
        /// Returns a <see cref="System.String"/> that represents this instance.
        /// </summary>
        /// <returns>
        /// A <see cref="System.String"/> that represents this instance.
        /// </returns>
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            string baseParams = base.ToString();
            if (!String.IsNullOrWhiteSpace(baseParams))
                sb.Append(baseParams).Append(",");

            // Handle AxisTitlesPosition
            if ((AxisTitlesPosition != TypeOfPosition.Out) && (AxisTitlesPosition != TypeOfPosition.Undefined))
                sb.Append("axisTitlesPosition: '").Append(AxisTitlesPosition.ToString().ToLower()).Append("',");


            if ((!String.IsNullOrWhiteSpace(GridLineColor)) && (Array.IndexOf(_gridLinecolorExclusion, GridLineColor.ToLower()) < 0))
                sb.Append("gridLineColor: '").Append(SecureString(GridLineColor)).Append("',");

            // Title Position
            if ((TitlePosition != TypeOfPosition.In) && (TitlePosition != TypeOfPosition.Undefined))
                sb.Append("titlePosition: '").Append(TitlePosition.ToString().ToLower()).Append("',");

            if (LineWidth != 2)
                sb.Append("lineWidth: ").Append(LineWidth).Append(",");

            if (PointSize > 0)
                sb.Append("pointSize: ").Append(PointSize).Append(",");

            if (IsStacked)
                sb.Append("isStacked: true,");

            // Removing the last comma
            sb.Remove(sb.Length - 1, 1);

            return sb.ToString();
        }
    }

}
